package cn.zhou.mapper;

import cn.zhou.domain.Role;
import cn.zhou.domain.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zy9524
 * @date 2019/6/9 19:51
 */
@Repository
public interface UserMapper {

    @Select("select * from users where username=#{username} and password=#{password}")
    User findUserByUsernameAndPassword(@Param("username") String username, @Param("password")String password);

    @Select("select * from users")
    @Results({
            @Result(property = "id" ,column = "id"),
            @Result(property = "username" ,column = "username"),
            @Result(property = "password" ,column = "password"),
            @Result(property = "sex" ,column = "sex"),
            @Result(property = "date" ,column = "birthday"),
            @Result(property = "roleList",
                    column = "id",
                    javaType = List.class,
                    many = @Many(select = "cn.zhou.mapper.RoleMapper.findByUid")
            )
    })
    List<User> findAllUser();

}
